package com.hrt.manage.users.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hrt.bean.UserVO;
import com.hrt.bean.UsersInfor;
import com.hrt.manage.users.dao.UsersInforDao;
import com.hrt.manage.users.service.UserInforService;


@Service
public class UserInforServiceImpls implements UserInforService {

	@Autowired
	private UsersInforDao dao;
	
	public UserInforServiceImpls() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public Long totalCount() {
		// TODO Auto-generated method stub
	
		return 	dao.totalCount();
	}

	

	@Override
	public List queryByPage(int pageIndex, int pageSize)  {
		// TODO Auto-generated method stub
		List list=new ArrayList();
		 list=dao.queryByPage(pageIndex, pageSize);
		return list;
	}

	@Override
	public void deleteById(Long[] ids) throws Exception {
		
		List<UsersInfor> users=dao.getByIds(ids);
		for(UsersInfor user:users)
		{
			user.setIsdelete(new Integer(1));
			dao.updateEntity(user);
		}
		
		
	}

	@Override
	public void saveUser(UsersInfor user) {
		
		dao.saveEntity(user);
		
		
	}

	@Override
	public void updateUser(UsersInfor user) {
		dao.updateEntity(user);
		
	}

	@Override
	public UsersInfor getUserByid(Long userId) {
		// TODO Auto-generated method stub
		return dao.getById(userId);
	}

	@Override
	public UsersInfor login(String loginName, String password) {
		// TODO Auto-generated method stub
		UsersInfor user=dao.login(loginName,password);
		
		return user;
	}

	@Override
	public UserVO getUserByUsernameAndPassword(String username, String password) {
		UsersInfor user=dao.login(username,password);
		if(user!=null){
			UserVO vo=new UserVO();
			vo.setLoinName(user.getLoginName());
			vo.setUserId(user.getId());
			vo.setPassword(user.getPassword());
			return vo;
		}
		return null;
	}

	

	
	
}
